package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Questions;
import com.qf.mapper.QuestionsMapper;
import com.qf.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 10537
 * @version V1.0
 * @Date 2021/10/6 16:41
 */
@Service
public class QuestionsServiceImpl implements QuestionsService {
    @Autowired
    private QuestionsMapper questionsMapper;

    @Override
    public PageInfo<Questions> findByPage(Integer page, Integer rows) {
        PageHelper.startPage(page,rows);
        List<Questions> questions = questionsMapper.selectByExample(null);
        PageInfo<Questions> pageInfo=new PageInfo<>(questions);
        return pageInfo;
    }

    @Override
    public void add(Questions questions) {
        int i = questionsMapper.insert(questions);
        if (i!=1){
            System.out.println("提问失败");
            throw new RuntimeException("提问失败");
        }
    }
}
